gcloud installation testing

This notebook has to be executed on a jupyter server where gcloud has been installed.


In [ ]:
#gcloud version
!gcloud -v

In [ ]:
#gcloud config
!gcloud config list

project is not set, so let try to set it


In [ ]:
#list projects
!gcloud projects list --format='[box]'

In [ ]:
#list the project in a more firendly way for python ;-)
!gcloud projects list --format='value[no-heading](name,project_ID)'

In [ ]:
#put the project list in a dictionnary
projects=!gcloud projects list --format='value[no-heading](name,project_ID)'
projectsDict={project[0]:project[1] for project in [line.split('\t')for line in projects.n.split('\n')]}

In [ ]:
# choose the projectId with a nice widget

import ipywidgets as widgets
#projectId is the variable that will contains the projectId that will be used in the API calls
projectId=None

projectsDict['None']='invalid'

#the dropdownlist widget
projectWidget=widgets.Dropdown(options=projectsDict,description='Choose your Project',value='invalid')
#a valid widget that get valid when a project is selected
projectIdValid=widgets.Valid(value=False,description='')
display(widgets.Box([projectWidget,projectIdValid]))

def projectValueChange(sender):
    if projectWidget.value!='invalid':
        #when a valid project is selected ,the gloabl variable projectId is set 
        projectIdValid.value=True
        projectIdValid.description=projectWidget.value
        global projectId
        projectId=projectWidget.value    
    else:
        projectIdValid.value=False
        projectIdValid.description=''
projectWidget.observe(projectValueChange, 'value')

In [ ]:
#we set the project in the gcloud config
!gcloud config set project {projectId}

In [ ]:
#we check it's correct
!gcloud config list

In [1]:
#we can now use gcloud without passing the project in the parameters!
!gcloud compute zones list


NAME                    REGION                STATUS  NEXT_MAINTENANCE  TURNDOWN_DATE
asia-east1-a            asia-east1            UP
asia-east1-b            asia-east1            UP
asia-east1-c            asia-east1            UP
asia-northeast1-c       asia-northeast1       UP
asia-northeast1-a       asia-northeast1       UP
asia-northeast1-b       asia-northeast1       UP
asia-southeast1-b       asia-southeast1       UP
asia-southeast1-a       asia-southeast1       UP
australia-southeast1-b  australia-southeast1  UP
australia-southeast1-a  australia-southeast1  UP
australia-southeast1-c  australia-southeast1  UP
europe-west1-c          europe-west1          UP
europe-west1-d          europe-west1          UP
europe-west1-b          europe-west1          UP
europe-west2-b          europe-west2          UP
europe-west2-c          europe-west2          UP
europe-west2-a          europe-west2          UP
us-central1-c           us-central1           UP
us-central1-a           us-central1           UP
us-central1-b           us-central1           UP
us-central1-f           us-central1           UP
us-east1-d              us-east1              UP
us-east1-c              us-east1              UP
us-east1-b              us-east1              UP
us-east4-b              us-east4              UP
us-east4-c              us-east4              UP
us-east4-a              us-east4              UP
us-west1-c              us-west1              UP
us-west1-b              us-west1              UP
us-west1-a              us-west1              UP

In [ ]: